using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
//ai参与度:1,仅提供部分方法
public class PlayerJump : MonoBehaviour//其实这是冲刺,我不会写冲刺英文,用JUMP代替罢
{
    public float jumpSpeed = 0.1f; 
    public float MaxJumpDowntime = 0.5f;//最大按下时间
    private Rigidbody2D rb2d;
    private Transform tf;
    private float MouseDowntime = 0f;
    public float JumpMaxCD = 5f;
    private float JumpCD = 0f;
    void Start()
    {
        rb2d = GetComponent<Rigidbody2D>();
        tf = GetComponent<Transform>();
    }

    // Update is called once per frame
    void Update()
    {
        JumpCD += Time.deltaTime;
        bool IsMouseButtonDown = Input.GetMouseButtonDown(0);
        bool IsMouseButtonUp = Input.GetMouseButtonUp(0);
        if (JumpCD < JumpMaxCD)
        {
            //占位,芝士之前的逻辑,懒得删掉了
            //JumpCD = Time.time - JumpTime;
        }
        else
        {
            if (IsMouseButtonDown)
            {
                MouseDowntime = Time.time;
            }
            if (IsMouseButtonUp)
            {
                float HoldMouseDowntime = Time.time - MouseDowntime;
                if (HoldMouseDowntime > MaxJumpDowntime)
                {
                    HoldMouseDowntime = MaxJumpDowntime;
                }
                Vector3 ForceDirection = new Vector3(Input.mousePosition.x - (Screen.width / 2), Input.mousePosition.y - (Screen.height / 2), 0f);
                rb2d.AddForce(ForceDirection * Mathf.Log(HoldMouseDowntime + 1f) * jumpSpeed * 0.5f, ForceMode2D.Force);
                JumpCD = 0f;
            }//嵌套多的像html...
        }
    }
}
